{include file="public/header" /}
</head>
<body>
<div style="margin: 20px;">
    <div class="demoTable">
        <div class="layui-inline" style="width:400px;">
            <input class="layui-input"  id="demoReload" autocomplete="off" placeholder="请输入案例编号，标题进行搜索，搜索以后不会保持树结构">
        </div>
        <button class="layui-btn" data-type="reload" id="reloadBtn"><i class="layui-icon">&#xe615;</i> 搜索</button>
    </div>
    <table class="layui-hide" id="LAY_table_menu" lay-filter="menu"></table>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">选中添加案例</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="add"><i class="layui-icon">&#xe608;</i> 添加案例&ensp;</a>
</script>
<script>
    layui.use('table', function(){
        var table = layui.table,form = layui.form;
        //监听工具条
        table.on('tool(menu)', function(obj){
            var data = obj.data;
            if(obj.event === 'add'){
                layer.confirm('确定要将编号 《'+data.project_no+'》 案例加入？', {
                    title:'添加案例',
                    skin: 'layui-layer-lan',
                    btn: ['确定','取消'] //按钮
                }, function(){
                    post_sub("{:url('Cases/importDesignCase')}",{"data": [data]},false,false);
                });
            }
        });
        //方法级渲染
        table.render({
            elem: '#LAY_table_menu'
            ,url: '{:url("Cases/addDesignCase",["table"=>1])}'
            ,cellMinWidth: 80
            ,height: 'full-100'
            ,cols: [[
                {checkbox: true}
                ,{field:'project_no',title: '编号',align:'center', width:120}
                ,{field:'demand',title: '设计需求',align:'center'}
                ,{title:'操作', toolbar: '#barDemo',width:120,align:'center'}
            ]]
            ,id: 'testReload'
            ,page: true
            ,toolbar:"#toolbarDemo"
            ,defaultToolbar:{$defaultToolbar}
            ,limit:"{$limit}"
            ,limits:[{$limits}]
            ,done:function () {

            }
        });
        //头部工具条监听事件
        table.on('toolbar(menu)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    if(checkStatus.data.length > 0) {
                        layer.confirm('确定要将选中的（' + checkStatus.data.length + '）个案例加入？重复案例会跳过！', {
                            title: '选中添加案例',
                            skin: 'layui-layer-lan',
                            btn: ['确定', '取消'] //按钮
                        }, function () {
                            post_sub("{:url('Cases/importDesignCase')}", {"data": checkStatus.data},false,false);
                        });
                    }else {
                        layer.msg("没有选中任何一行");
                    }
                    break;
            };
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('testReload', {
                    where: {
                        tables:1,
                        keyword: demoReload.val(),
                    },
                    page: {
                        curr: 1
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $("#demoReload").keydown(function(event){
            var keycode = (event.keyCode ? event.keyCode : event.which);
            if(keycode == '13'){
                //回车触发
                $('#reloadBtn').trigger('click');
            }
        });
    });

</script>
</body>
</html>